<hr/>
<div class="control-group">
    <label class="control-label">Size options</label>
    <div class="controls">
        <label>Width</label>
        <input type="text" name="Block[width]" value="<?php echo $blockModel->width ?>" />
    </div>
</div>
<div class="control-group">
    <label class="control-label">Height</label>
    <div class="controls">
        <label>Width</label>
        <input type="text" name="Block[height]" value="<?php echo $blockModel->height ?>" />
    </div>
</div>
<div class="control-group">
    <label class="control-label">Auto Resize</label>
    <div class="controls">
        <select name="Block[autoResize]">
            <option value="1">Yes</option>
            <option value="0" <?php if(!$blockModel->autoResize) echo 'selected' ?>>No</option>
        </select>
    </div>
</div>
<hr/>
<?php $i = 0; foreach($blockModel->images as $image) : ?>
    <div class="control-group imageWrapper">
        <label class="control-label">Image <?php echo ++$i ?></label>
        <div class="controls">
            <label>Title</label>
            <input type="text" name="image[<?php echo $i ?>][title]" class="span5" value="<?php echo $image['title'] ?>" />
            <label>Description</label>
            <textarea name="image[<?php echo $i ?>][description]" class="span5"><?php echo $image['description'] ?></textarea>
            <label>Url</label>
            <input type="url" name="image[<?php echo $i ?>][url]" class="span5" value="<?php echo $image['url'] ?>" />
            <input type="hidden" name="image[<?php echo $i ?>][oldimage]" value="<?php echo $image['filePath'] ?>" />
            <label>Select image (if needed)</label>
            <img src="<?php echo ImageHelper::thumb(300, 200, $image['filePath']) ?>" />
            <br/>
            <input type="file" name="image[<?php echo $i ?>][newimage]" />

            <br/>
            <a class="btn btn-danger removeImage">Remove</a>
        </div>
    </div>
<hr/>
<?php endforeach; ?>

<div class="control-group imageWrapper">
    <label class="control-label">New image</label>
    <div class="controls">
        <label>Title</label>
        <input type="text" name="image[<?php echo ++$i ?>][title]" class="span5" />
        <label>Description</label>
        <textarea name="image[<?php echo $i ?>][description]" class="span5"></textarea>
        <label>Url</label>
        <input type="url" name="image[<?php echo $i ?>][url]" class="span5" />
        <input type="hidden" name="image[<?php echo $i ?>][oldimage]" />
        <label>Select image</label>
        <input type="file" name="image[<?php echo $i ?>][newimage]" class="span5" />
    </div>
</div>

<script>
    $(document).ready(function(){
        $(".removeImage").click(function(){
            if(confirm("Are you sure?")){
                $(this).closest(".imageWrapper").remove();
            }
        });
    });
</script>
